//
//  FANWelcomeViewController.swift
//  Weibo - Swift
//
//  Created by user on 16/4/19.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

class FANWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()

    }
    
    func setupUI(){
        
        view.backgroundColor = UIColor(white: 247/255, alpha: 1)
        
        view.addSubview(iconImageView)
        
        view.addSubview(label)
        
        iconImageView.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)
            
            make.top.equalTo(view).offset(200)
            
            make.size.equalTo(CGSize(width: 80, height: 80))
        }
        
        label.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)
            
            make.top.equalTo(iconImageView.snp_bottom).offset(15)
            
        }
        
 
        iconImageView.layer.cornerRadius = 40
        
        iconImageView.layer.masksToBounds = true
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        iconImageView.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(100)
        }
        
        UIView.animateWithDuration(1, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layer.layoutIfNeeded()
            
            }) { (_) -> Void in
                
              UIView.animateWithDuration(1, animations: { () -> Void in
                
                self.label.alpha = 1
                
                }, completion: { (_) -> Void in
                    
                    NSNotificationCenter.defaultCenter().postNotificationName(FANChangeRootVCNotification, object: self)
                    
//                    UIApplication.sharedApplication().keyWindow?.rootViewController = FANMainTabController()
              })
                
        }
    }
    
    lazy var iconImageView:UIImageView = {
    
        let imageView = UIImageView()
        
        imageView.image = UIImage(named:"avatar_default_big")
        
        if let imageName = FANUserNetModel.sharedUserModel.account?.avatar_large{
            
        imageView.sd_setImageWithURL(NSURL(string: imageName), placeholderImage: UIImage(named: "avatar_default_big"))
            
        }
        
        
        return imageView
    
    }()
    
    lazy var label:UILabel = {
    
        let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15)
        
        label.alpha = 0
        
        label.text = "欢迎回来"
        
        return label
        
    }()
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
